package com.atguigu.gmall.realtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ming
 * @date 2022/11/23
 * IK分词器工具类
 */
public class KeywordUtil {
    public static List<String> analyze(String text) {
        List<String> keywordList = new ArrayList<>();

        StringReader reader = new StringReader(text);
        IKSegmenter ik = new IKSegmenter(reader, true);

        try {
            Lexeme word = null;
            while ((word = ik.next()) != null) {
                keywordList.add(word.getLexemeText());
            }

        } catch (IOException ex) {

            throw new RuntimeException(ex);

        }
        return keywordList;
    }

    public static void main(String[] args) {
        System.out.println(analyze("Apple iPhoneXSMax (A2104) 256GB 深空灰色 移动联通电信4G手机 双卡双待"));
    }
}
